package org.yiming.utdemo.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@RequiredArgsConstructor
@Service
public class ServiceAImpl implements ServiceA {

    private final ServiceB serviceB;

    @Override
    public Result business1(String param) {
        Boolean result = serviceB.businessB();
        if (result) {
            return Result.builder().success(true).build();
        }
        return Result.builder().success(false).build();
    }

    @Override
    public String business2() {
        serviceB.businessB();
        return "ok";
    }

    @Override
    public Result business3() throws Exception {
        try {
            serviceB.businessB();
            return Result.builder().success(true).build();
        } catch (Exception e) {
            log.error("error");
        }
        return Result.builder().success(false).build();
    }

    @Override
    public Result business4(String param) {
        Boolean result = MyUtil.parse(param);
        if (result) {
            return Result.builder().success(true).build();
        }
        return Result.builder().success(false).build();
    }

    @Override
    public Result business5(String param) {
        Boolean result = business5_1(param);
        if (result) {
            return Result.builder().success(true).build();
        }
        return Result.builder().success(false).build();
    }

    private Boolean business5_1(String param) {
        return true;
    }

    @Override
    public Result business6(String param) {
        BusinessDTO businessDTO = new BusinessDTO();
        if (businessDTO.getAge() > 20) {
            return Result.builder().success(true).build();
        }
        return Result.builder().success(false).build();
    }

    @Override
    public Result business7(String param) {
        for (int i = 0; i < 10; i++) {
            serviceB.businessB();
        }
        return Result.builder().success(true).build();
    }
}
